import { useState, useEffect } from "react"

const getUser = (): Promise<string> => {
  return new Promise((resolve, reject) => {
    window.setTimeout(() => {
      resolve("success")
    }, 2000)
  })
}

const useGetUserInfo = () => {
  const [userInfo, setUserInfo] = useState("")
  const [loading, setLoading] = useState(true)

  useEffect(() => {
    getUser().then((userInfo) => {
      setUserInfo(userInfo)
      setLoading(false)
    })
  }, [])

  return { userInfo, loading }
}

export default useGetUserInfo
